
# encoding:utf-8
# encoding:utf-8
from flask import Flask, jsonify, render_template
import sqlite3

app = Flask(__name__)

# 数据库查询函数
def query_db(query, args=(), one=False):
    conn = sqlite3.connect('database.db')
    cur = conn.execute(query, args)
    rv = cur.fetchall()
    cur.close()
    conn.close()
    return (rv[0] if rv else None) if one else rv

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/users')
def get_users():
    users = query_db('SELECT * FROM users')
    return jsonify(users)

if __name__ == '__main__':
    app.run(debug=True)